<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 表单
                </el-breadcrumb-item>
                <el-breadcrumb-item>员工添加</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="员工名">
                        <el-input type="text" rows="5" v-model="form.ename"></el-input>
                    </el-form-item>
                    <el-form-item label="用户名">
                        <el-input type="text" rows="5" v-model="form.eusername"></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input type="text" rows="5" v-model="form.epass"></el-input>
                    </el-form-item>
                    <el-form-item label='性别'>
                        <el-radio-group v-model="form.sex">
                            <el-radio label="男"/>
                            <el-radio label="女"/>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label='手机号'>
                        <el-input type="text" rows="5" v-model="form.tel"></el-input>
                    </el-form-item>
                    <el-form-item label='身份证号'>
                        <el-input type="text" rows="5" @blur='getsex' v-model="form.idcard"></el-input>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">提交</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'empadd',
    data() {
        return {
            fileList: [],
            form:{}
        };
    },
    methods: {

        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${ file.name }？`);
        },
        onSubmit() {
            this.form.sex= this.form.idcard.substring(16,17)%2==0?'女':'男';
            this.$http({
                method:'post',
                url:'emp/empAdd',
                params:{ename:this.form.ename,eusername:this.form.eusername,epass:this.form.epass,sex:this.form.sex
                ,tel:this.form.tel,idcard:this.form.idcard
                }
            }).then((res)=>{
                if(res!=false){
                    this.$message.success('提交成功跳转到认证界面！');
                    this.$router.push({path:'/empauth',query: {eusername:this.form.eusername}})
                }else {
                    this.$message.error(res);
                }
            })

        }
    }
};
</script>